home *** CD-ROM | disk | FTP | other *** search
- /*
- * nuke.c
- *
- * this is a secure file deletion command
- * written by Giovanni Gigante, 4 march 1994, V 1.0
- * this code is freeware
- *
- * CAUTION: read the enclosed document before using.
- *
- */
-
- #include <stdio.h>
- #include <stdlib.h>
-
- #define N_PASSES 3
- #define EXIT_BAD 20
- #define EXIT_WARN 10
-
- void main(int argc, char *argv[]) {
-
- FILE *fp;
- long length;
- int i,j;
- const char version[]="$VER: 1.0 950304";
- const int fill[N_PASSES]={0x00,0xff,0x00};
-
- /* check CLI syntax */
- if (argc != 2) {
- fprintf(stderr,"Nuke 1.0 by Giovanni Gigante\n");
- fprintf(stderr,"Usage: %s <filename>\n",argv[0]);
- exit(EXIT_BAD);
- }
-
- /* open file and get its length*/
- if(!(fp=fopen(argv[1],"r"))) {
- fprintf(stderr,"Cannot open %s\n",argv[1]);
- exit(EXIT_BAD);
- }
- if(fseek(fp,0,SEEK_END)) exit(EXIT_BAD);
- length=ftell(fp);
-
- /* overwrite file several times */
- for(j=0; j<N_PASSES; j++) {
- if(!(fp=freopen(argv[1],"w",fp))) {
- fprintf(stderr,"Cannot reopen %s at pass %d\n",argv[1],j);
- exit(EXIT_BAD);
- }
- for(i=0; i<=length; i++) {
- if (fputc(fill[j],fp)==EOF) {
- fprintf(stderr,"Cannot write to %s\n",argv[1]);
- exit(EXIT_BAD);
- }
- }
- fclose(fp);
- }
-
- /* delete file */
- if(remove(argv[1])) {
- fprintf(stderr,"%s overwritten, but cannot be deleted\n",argv[1]);
- exit(EXIT_WARN);
- }
-
- fprintf(stderr,"%s Nuked.\n",argv[1]);
- } /*main*/
-
-